package com.zzj.ecology.system.service.impl.minitor;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzj.ecology.system.bean.minitor.SysUserOnline;
import com.zzj.ecology.system.bean.minitor.SysUserOnlineExample;
import com.zzj.ecology.system.mapper.minitor.SysUserOnlineMapper;
import com.zzj.ecology.system.service.minitor.SysUserOnlineService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service("sysUserOnlineService")
@Transactional(rollbackFor = Exception.class)
public class SysUserOnlineServiceImpl implements SysUserOnlineService {

    @Autowired
    private SysUserOnlineMapper sysUserOnlineMapper;


    /**
     * 用户认证成功 创建在线SESSION
     * @param userOnline
     * @return
     */
    public int insert(SysUserOnline userOnline) {
        return sysUserOnlineMapper.insert(userOnline);
    }

    /**
     * 更新用户状态
     * @param userOnline
     * @return
     */
    public int updateStatus(SysUserOnline userOnline) {
        return sysUserOnlineMapper.updateByPrimaryKeySelective(userOnline);
    }

    /**
     * 根据 状态 查询所有 Session
     * @return
     */
    public List<SysUserOnline> findSessionsByStatus(String status) {
        SysUserOnlineExample example = new SysUserOnlineExample();
        example.createCriteria().andStatusEqualTo(status);
        return sysUserOnlineMapper.selectByExample(example);
    }
}
